import datetime
import json
import re
import time

import requests
from flask import Flask, request, render_template, jsonify

app = Flask(__name__)


class ITAM():
    def __init__(self, checkbox_value, text_value, number_value):
        self.checkbox_value = checkbox_value  # 工区
        self.text_value = text_value  # 通行证
        self.number_value = number_value  # 工号
        self.session = requests.Session()
        self.headers = {
            'Authorization': self.text_value,
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
        }

    def get_url(self):
        global id
        regionId = self.checkbox_value
        if regionId == '科技绿洲10号楼':
            id = 6883757284879551496
        elif regionId == '科技绿洲24号楼':
            id = 6883757282409106446
        elif regionId == '漕河泾B座':
            id = 7012860924495694860
        elif regionId == '漕河泾C座':
            id = 6985100232698645536
        elif regionId == '漕河泾D座':
            id = 7022928524357176351
        elif regionId == '虹桥国际':
            id = 6956842757553998861
        elif regionId == '尚浦3':
            id = 7120333627480951847
        elif regionId == '尚浦6':
            id = 6947981682733829134
        elif regionId == '尚浦9':
            id = 7003162557436398622
        elif regionId == '尚浦8':
            id = 6968329907891293197
        elif regionId == '尚浦11':
            id = 7002906691436760068
        elif regionId == '尚浦5':
            id = 7137641450603039782
        if regionId in ['科技绿洲24号楼', '漕河泾C座', '尚浦11']:
            url1 = 'https://asset.bytedance.net/api/v1/asset/appropriate/list?subStatus=1001&regionId={}&receiveType=0&applySourceList=0%2C2%2C3%2C4&search=&pageNum=1&pageSize=100&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
                id)
            url2 = 'https://asset.bytedance.net/api/v1/asset/borrow/list?regionIDList={}&subStatus=1501&pageNum=1&pageSize=10&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
                id)
            url3 = 'https://asset.bytedance.net/api/v1/asset/repair/list?sorter%5Bfield%5D=&sorter%5BisDesc%5D=false&pageNum=1&pageSize=10&subStatus=1301&regionId={}'.format(
                id)
            url4 = ' https://asset.bytedance.net/api/v1/asset/return/list?subStatus=1101&regionId={}&OfficeIDList%5B%5D={}&pageNum=1&pageSize=10&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
                id, id)
            url5 = 'https://asset.bytedance.net/api/v1/asset/repurchase/list?sorter%5Bfield%5D=&sorter%5BisDesc%5D=false&pageNum=1&pageSize=10&subStatus=1203&regionId={}'.format(
                id)
        else:

            url1 = 'https://asset.bytedance.net/api/v1/asset/appropriate/list?subStatus=1001&applySourceList=0%2C2%2C3%2C4&regionId={}&search=&pageNum=1&pageSize=100&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
                id)
            url2 = 'https://asset.bytedance.net/api/v1/asset/borrow/list?regionIDList={}&subStatus=1501&pageNum=1&pageSize=10&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
                id)
            url3 = 'https://asset.bytedance.net/api/v1/asset/repair/list?sorter%5Bfield%5D=&sorter%5BisDesc%5D=false&pageNum=1&pageSize=10&subStatus=1301&regionId={}'.format(
                id)
            url4 = ' https://asset.bytedance.net/api/v1/asset/return/list?subStatus=1101&regionId={}&OfficeIDList%5B%5D={}&pageNum=1&pageSize=10&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
                id, id)
            url5 = 'https://asset.bytedance.net/api/v1/asset/repurchase/list?sorter%5Bfield%5D=&sorter%5BisDesc%5D=false&pageNum=1&pageSize=10&subStatus=1203&regionId={}'.format(
                id)
        return url1, url2, url3, url4, url5, id

    def apply_return(self, number2_value):
        global rest3
        self.number2_value = number2_value

        if re.match(r'^IT.+$', self.number2_value):
            self.url1 = 'https://asset.bytedance.net/api/v1/asset/return/returnableList?' \
                        'current=1&pageSize=100&searchStr={}&statusList=1%2C2&subStatusList=18%2C19%2C12'.format(
                self.number2_value)
            self.url2 = 'https://asset.bytedance.net/api/v1/asset/return/batchReturn'
            self.url3 = 'https://asset.bytedance.net/api/v1/asset/return/receive/detail'
            res = self.session.get(url=self.url1, headers=self.headers).json()
            # print(res)
            if res['data']['AssetDetails'] != []:
                dic = res['data']['AssetDetails'][0]['AssetBasicInfo']['ID']
                # print(dic)
                data = {'assetIDList': ['{}'.format(dic)],
                        'reason': '归还',
                        'regionId': "{}".format(self.get_url()[5])  # 退库到科技绿洲10号楼
                        }
                # print(data)
                res2 = self.session.post(url=self.url2, json=data, headers=self.headers).json()
                # print(res2)
                dic1 = res2['data']['FlowIDs'][0]
                data1 = {'IDs': ['{}'.format(dic1)]
                         }
                rest3 = self.session.post(url=self.url3, json=data1, headers=self.headers).json()
                # print('===================%s已发起退库===================' % (self.number.get()))  # 退库已经成功

    def dic_return(self, number2_value):
        self.number2_value = number2_value
        global res5, rest7, rest8

        if re.match(r'^IT.+$', self.number2_value):
            self.url = 'https://asset.bytedance.net/api/v1/asset/return/list?search={}&pageNum=1&pageSize=100&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
                self.number2_value)
            self.url2 = 'https://asset.bytedance.net/api/v1/asset/return/taking'
            self.url3 = 'https://asset.bytedance.net/api/v1/asset/return/receive/detail'
            self.url4 = 'https://asset.bytedance.net/api/v1/asset/return/receive'
            self.url5 = 'https://asset.bytedance.net/api/v1/asset/return/confirmAssetReturn'
            self.url6 = 'https://asset.bytedance.net/tanna/api/widget/v1/employee/list'
            res4 = self.session.get(url=self.url, headers=self.headers).json()['data']['AssetReturnList'][0]['ID']
            # 获取到使用人、 资产类型
            # ApplyUser = self.session.get(url=self.url, headers=self.headers).json()['data']['AssetReturnList'][0]['ApplyUser']
            # print(ApplyUser)
            # AssetTypeNameZh = self.session.get(url=self.url, headers=self.headers).json()['data']['AssetReturnList'][0]['AssetInfo'][0]['AssetTypeNameZh']
            data1 = {"FlowID": "{}".format(res4),
                     "Assignee": "{}@bytedance.people".format(int(self.number_value))}  # 处理人为自己
            res5 = self.session.post(url=self.url2, json=data1, headers=self.headers)  # 接单
            data2 = {"IDs": ["{}".format(res4)]}
            rest7 = self.session.post(url=self.url3, json=data2, headers=self.headers)
            data3 = {"FlowIDs": ["{}".format(res4)]}
            rest8 = self.session.post(url=self.url4, json=data3, headers=self.headers)
            res8 = self.session.get(url=self.url, headers=self.headers).json()['data']['AssetReturnList'][0]['ID']
            data4 = {"flowIDs": ["{}".format(res8)],
                     "returnRegionID": "{}".format(self.get_url()[5])}  # 退库到10号楼

            rest9 = self.session.post(url=self.url5, json=data4, headers=self.headers).json()

        # 下面是退库擦除

    def erase(self, cookie_value, pass_value):
        self.cookie_value = cookie_value
        self.pass_value = pass_value
        false = None
        true = None
        null = None
        session = requests.session()
        url = 'https://asset.bytedance.net/api/v1/asset/return/list?search={}&pageNum=1&pageSize=100&sorter%5Bfield%5D=&sorter%5BisDesc%5D=false'.format(
            self.number2_value)
        res6 = requests.get(url=url, headers=self.headers).json()['data']['AssetReturnList'][0]['AssetInfo'][0][
            'AssetTypeNameZh']
        if res6 == '主机':
            url = 'https://apaas.feishuapp.cn/ae/api/v1/workflow/namespaces/package172__c/start'
            url2 = 'https://apaas.feishuapp.cn/ae/api/v1/workflow/namespaces/package172__c/form/completeGlobalForm'
            headers = {
                'Cookie': '{}'.format(self.cookie_value),
                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
                'X-Kunlun-Token': '{}'.format(self.pass_value)
            }
            data = {"sourceWorkflowId": "1763777146369107"}
            res = session.post(url=url, json=data, headers=headers).json()['data']['data']['formInstanceId']
            data2 = {"form": {"_initialRecord__proposed__f1fdd3ee": {
                "package172__c__text_aadeicaozlobi1681956338948z3db90u1pbfthnge": "{}".format(self.number2_value)}},
                "objectId": 1763666463216647,
                "properties": {"_initialRecord__proposed__f1fdd3ee": {
                    "package172__c__text_aadeicaozlobi1681956338948z3db90u1pbfthnge": {
                        "alias": [{"language_code": 2052, "text": "IT资产号"}],
                        "componentId": "_initialRecord__proposed__f1fdd3ee_text_aadeicaozlobi1681956338948z3db90u1pbfthnge_text",
                        "customEvents": {"fieldOnBlur": [], "fieldOnChange": [{
                            "apiName": "event__initialRecord__proposed__f1fdd3ee_text_aadeicaozlobi1681956338948z3db90u1pbfthnge_text_fieldOnChange_1683791342109",
                            "label": "判断资产号",
                            "previewPath": ""}]},
                        "defaultValue": {"type": "value"}, "layout": [], "placeholder": [], "readonly": false,
                        "required": true, "scanEditable": true, "scanEnable": true, "tooltip": [], "type": "text",
                        "width": 100}}}, "formInstanceId": int('{}'.format(res)),
                "sourceWorkflowId": "1763777146369107",
                "version": "v2"}
            res2 = session.post(url=url2, json=data2, headers=headers)
            url3 = 'https://apaas.feishuapp.cn/ae/api/v2/layout/namespaces/package172__c/table/runtime/data'
            data3 = {"describeFilter": {"filter": {"api_name": "", "biz_type": "", "conditions": [{"index": 0,
                                                                                                   "left": {
                                                                                                       "displayName": null,
                                                                                                       "fieldsDisplayNames": null,
                                                                                                       "settings": {
                                                                                                           "fieldPath": [
                                                                                                               {
                                                                                                                   "extendLogic": null,
                                                                                                                   "extendLogicTags": [],
                                                                                                                   "fieldApiName": "package172__c__lookup_aadeicaozlobi1681956384515ifoy5lgfq89cgrcc",
                                                                                                                   "fieldId": 0,
                                                                                                                   "isMultiple": false,
                                                                                                                   "isSubField": false,
                                                                                                                   "objectApiName": "package172__c__object_aadeicdjdw6co",
                                                                                                                   "objectId": 0}],
                                                                                                           "valueVersion": "",
                                                                                                           "variableApiName": "current_object",
                                                                                                           "variableType": "lookup"},
                                                                                                       "status": "",
                                                                                                       "type": "metadataVariable"},
                                                                                                   "operator": "equals",
                                                                                                   "right": {
                                                                                                       "displayName": null,
                                                                                                       "fieldsDisplayNames": null,
                                                                                                       "settings": {
                                                                                                           "fieldPath": [
                                                                                                               {
                                                                                                                   "extendLogic": null,
                                                                                                                   "extendLogicTags": [],
                                                                                                                   "fieldApiName": "_id",
                                                                                                                   "fieldId": 0,
                                                                                                                   "isMultiple": false,
                                                                                                                   "isSubField": false,
                                                                                                                   "objectApiName": "_user",
                                                                                                                   "objectId": 0}],
                                                                                                           "valueVersion": "",
                                                                                                           "variableApiName": "current_user",
                                                                                                           "variableType": "lookup"},
                                                                                                       "status": "",
                                                                                                       "type": "metadataVariable"}},
                                                                                                  {"index": 0,
                                                                                                   "left": {
                                                                                                       "displayName": null,
                                                                                                       "fieldsDisplayNames": null,
                                                                                                       "settings": {
                                                                                                           "fieldPath": [
                                                                                                               {
                                                                                                                   "extendLogic": null,
                                                                                                                   "extendLogicTags": [],
                                                                                                                   "fieldApiName": "package172__c__option_aadeicaozlobi1681956406883nhbw7k649itutld4",
                                                                                                                   "fieldId": 0,
                                                                                                                   "isMultiple": false,
                                                                                                                   "isSubField": false,
                                                                                                                   "objectApiName": "package172__c__object_aadeicdjdw6co",
                                                                                                                   "objectId": 0}],
                                                                                                           "valueVersion": "",
                                                                                                           "variableApiName": "current_object",
                                                                                                           "variableType": "enum"},
                                                                                                       "status": "",
                                                                                                       "type": "metadataVariable"},
                                                                                                   "operator": "isAnyOf",
                                                                                                   "right": {
                                                                                                       "displayName": null,
                                                                                                       "fieldsDisplayNames": null,
                                                                                                       "settings": {
                                                                                                           "data": [
                                                                                                               "package172__c__option_1682227412380_aadeisx2eo4di4gs",
                                                                                                               "package172__c__option_1681956406885_aadeicaozlobi1681956406885mnfs16801r8s77bw"]},
                                                                                                       "status": "",
                                                                                                       "type": "constant"}}],
                                                   "logic": "", "use_fx_editor": "", "use_type": "", "version": "v2"},
                                        "appFilterIndex": []}, "size": 20, "page": null,
                     "sort": [{"direction": "desc", "field": "_updatedAt", "isFormula": false, "type": "number"}],
                     "authorize": {"appId": 1730064493499447, "appPageName": "iyeqgc1vj8aefd_vlsbse8"},
                     "fields": ["package172__c__option_aadeicaozlobi1681956406883nhbw7k649itutld4",
                                "package172__c__lookup_aadeicaozlobi1681956315030ztzp7c93ej0wveam",
                                "package172__c__email_aadejmibs2eeqxc6",
                                "package172__c__text_aadeicaozlobi1681956338948z3db90u1pbfthnge",
                                "package172__c__text_aadeicaozlobi16819563445762nj3c6evt8rsyfwc",
                                "package172__c__text_aadeicaozlobi1681956599453qf6j205rterhbyz9",
                                "package172__c__option_aadejimt2k2b4yv7", "package172__c__option_aadejimt2k2b4xgf",
                                "package172__c__datetime_aadeicaozlobi1681956354265xd1yzjbg4mfaf0gh",
                                "package172__c__datetime_aadeicaozlobi1681956360494r0k5k3jarp1zav3t",
                                "package172__c__datetime_aadeicaozlobi1681956367382djzco4khw8yma3bm",
                                "package172__c__lookup_aadeicaozlobi1681956384515ifoy5lgfq89cgrcc", "_id"],
                     "objectId": 1763666463216647, "objectApiName": "package172__c__object_aadeicdjdw6co", "actions": [
                    {"objectId": 1763666463216647, "actionId": 1767918746294296, "recordSetting": [{"type": "field",
                                                                                                    "setting": [{
                                                                                                        "objectApiName": "package172__c__object_aadeicdjdw6co",
                                                                                                        "fieldApiName": "_id"}],
                                                                                                    "variableApiName": "_initialRecord__original__f1fdd3ee"}]},
                    {"objectId": 1763666463216647, "actionId": 1763666465371213, "recordSetting": [{"type": "field",
                                                                                                    "setting": [{
                                                                                                        "objectApiName": "package172__c__object_aadeicdjdw6co",
                                                                                                        "fieldApiName": "_id"}],
                                                                                                    "variableApiName": "customizeInput__original__djdw6co"}]},
                    {"objectId": 1763666463216647, "actionId": 1764223808832571, "recordSetting": [{"type": "field",
                                                                                                    "setting": [{
                                                                                                        "objectApiName": "package172__c__object_aadeicdjdw6co",
                                                                                                        "fieldApiName": "_id"}],
                                                                                                    "variableApiName": "_initialRecord__original__f1fdd3ee"}]},
                    {"objectId": 1763666463216647, "actionId": 1767918746293304, "recordSetting": [{"type": "field",
                                                                                                    "setting": [{
                                                                                                        "objectApiName": "package172__c__object_aadeicdjdw6co",
                                                                                                        "fieldApiName": "_id"}],
                                                                                                    "variableApiName": "_initialRecord__original__f1fdd3ee"}]}],
                     "fromComponent": "table"}
            res3 = session.post(url=url3, json=data3, headers=headers).json()['data']['items'][0]['recordId']
            data4 = {"sourceWorkflowId": "1763776984931339",
                     "objectApiName2RecordIds": {"package172__c__object_aadeicdjdw6co": [int('{}'.format(res3))]},
                     "variables": "[]"}
            res4 = session.post(url=url, json=data4, headers=headers).json()['data']['data']['form'][
                '_initialRecord__proposed__f1fdd3ee']
            sj = res4['package172__c__datetime_aadeicaozlobi1681956354265xd1yzjbg4mfaf0gh']
            name1 = res4['package172__c__lookup_aadeicaozlobi1681956315030ztzp7c93ej0wveam']['i18n_name'][0]['text']
            id1 = res4['package172__c__lookup_aadeicaozlobi1681956315030ztzp7c93ej0wveam']['id']
            name2 = res4['package172__c__lookup_aadeicaozlobi1681956315030ztzp7c93ej0wveam']['name']
            modle = res4['package172__c__text_aadeicaozlobi1681956599453qf6j205rterhbyz9']
            sn = res4['package172__c__text_aadeicaozlobi16819563445762nj3c6evt8rsyfwc']
            id2 = session.post(url=url, json=data4, headers=headers).json()['data']['data']['formInstanceId']

            data5 = {"form": {"_initialRecord__proposed__f1fdd3ee": {
                "package172__c__datetime_aadeicaozlobi1681956354265xd1yzjbg4mfaf0gh": int('{}'.format(sj)),
                "package172__c__datetime_aadeicaozlobi1681956360494r0k5k3jarp1zav3t": null,
                "package172__c__datetime_aadeicaozlobi1681956367382djzco4khw8yma3bm": null,
                "package172__c__lookup_aadeicaozlobi1681956315030ztzp7c93ej0wveam": {
                    "avatar": {"color": null, "color_id": "", "content": null, "image": {
                        "large": "https://s1-imfile.feishucdn.com/static-resource/v1/v2_efecca58-07fd-492b-8571-6481fa04c97g~?image_size=noop&cut_type=&quality=&format=png&sticker_format=.webp"},
                               "source": "image"},
                    "i18n_name": [{"language_code": 1033, "text": "{}".format(name1)},
                                  {"language_code": 2052, "text": "{}".format(name2)}],
                    "id": int('{}'.format(id1)), "is_deleted": false, "name": "{}".format(name2)},
                "package172__c__text_aadeicaozlobi1681956338948z3db90u1pbfthnge": "{}".format(self.number2_value),
                "package172__c__text_aadeicaozlobi16819563445762nj3c6evt8rsyfwc": "{}".format(sn),
                "package172__c__text_aadeicaozlobi1681956599453qf6j205rterhbyz9": "{}".format(modle)}},
                "objectId": 1763666463216647,
                "properties": {"_initialRecord__proposed__f1fdd3ee": {
                    "package172__c__text_aadeicaozlobi1681956338948z3db90u1pbfthnge": {"alias": [],
                                                                                       "componentId": "_initialRecord__proposed__f1fdd3ee_text_aadeicaozlobi1681956338948z3db90u1pbfthnge_text",
                                                                                       "defaultValue": {
                                                                                           "type": "value"},
                                                                                       "layout": [], "placeholder": [],
                                                                                       "readonly": true,
                                                                                       "required": true,
                                                                                       "scanEditable": true,
                                                                                       "scanEnable": false,
                                                                                       "tooltip": [],
                                                                                       "type": "text", "width": 50},
                    "package172__c__text_aadeicaozlobi16819563445762nj3c6evt8rsyfwc": {"alias": [],
                                                                                       "componentId": "_initialRecord__proposed__f1fdd3ee_text_aadeicaozlobi16819563445762nj3c6evt8rsyfwc_text",
                                                                                       "defaultValue": {
                                                                                           "type": "value"},
                                                                                       "layout": [], "placeholder": [],
                                                                                       "readonly": false,
                                                                                       "required": true,
                                                                                       "scanEditable": true,
                                                                                       "scanEnable": true,
                                                                                       "tooltip": [],
                                                                                       "type": "text", "width": 50},
                    "package172__c__text_aadeicaozlobi1681956599453qf6j205rterhbyz9": {"alias": [],
                                                                                       "componentId": "_initialRecord__proposed__f1fdd3ee_text_aadeicaozlobi1681956599453qf6j205rterhbyz9_text",
                                                                                       "defaultValue": {
                                                                                           "type": "value"},
                                                                                       "layout": [], "placeholder": [],
                                                                                       "readonly": true,
                                                                                       "required": false,
                                                                                       "scanEditable": true,
                                                                                       "scanEnable": false,
                                                                                       "tooltip": [],
                                                                                       "type": "text", "width": 50},
                    "package172__c__datetime_aadeicaozlobi1681956354265xd1yzjbg4mfaf0gh": {"alias": [],
                                                                                           "componentId": "_initialRecord__proposed__f1fdd3ee_datetime_aadeicaozlobi1681956354265xd1yzjbg4mfaf0gh_datetime",
                                                                                           "defaultValue": {
                                                                                               "type": "value"},
                                                                                           "hidden": false,
                                                                                           "layout": [],
                                                                                           "placeholder": [],
                                                                                           "readonly": true,
                                                                                           "required": false,
                                                                                           "scanEditable": true,
                                                                                           "scanEnable": false,
                                                                                           "tooltip": [],
                                                                                           "type": "datetime",
                                                                                           "width": 50},
                    "package172__c__datetime_aadeicaozlobi1681956360494r0k5k3jarp1zav3t": {"alias": [],
                                                                                           "componentId": "_initialRecord__proposed__f1fdd3ee_datetime_aadeicaozlobi1681956360494r0k5k3jarp1zav3t_datetime",
                                                                                           "defaultValue": {
                                                                                               "type": "value"},
                                                                                           "hidden": true, "layout": [],
                                                                                           "placeholder": [],
                                                                                           "readonly": true,
                                                                                           "required": false,
                                                                                           "scanEditable": true,
                                                                                           "scanEnable": false,
                                                                                           "tooltip": [],
                                                                                           "type": "datetime",
                                                                                           "width": 50},
                    "package172__c__datetime_aadeicaozlobi1681956367382djzco4khw8yma3bm": {"alias": [],
                                                                                           "componentId": "_initialRecord__proposed__f1fdd3ee_datetime_aadeicaozlobi1681956367382djzco4khw8yma3bm_datetime",
                                                                                           "defaultValue": {
                                                                                               "type": "value"},
                                                                                           "hidden": true, "layout": [],
                                                                                           "placeholder": [],
                                                                                           "readonly": true,
                                                                                           "required": false,
                                                                                           "scanEditable": true,
                                                                                           "scanEnable": false,
                                                                                           "tooltip": [],
                                                                                           "type": "datetime",
                                                                                           "width": 50},
                    "package172__c__lookup_aadeicaozlobi1681956315030ztzp7c93ej0wveam": {
                        "alias": [{"language_code": 2052, "text": "设备使用人"}],
                        "componentId": "_initialRecord__proposed__f1fdd3ee_lookup_aadeicaozlobi1681956315030ztzp7c93ej0wveam_lookup",
                        "defaultValue": {"generateRule": "", "reference": null, "type": "value", "value": null},
                        "layout": [], "placeholder": [], "readonly": false, "required": true, "scanEditable": true,
                        "scanEnable": false, "tooltip": [], "type": "lookup", "width": 100}}},
                "formInstanceId": int('{}'.format(id2)), "sourceWorkflowId": "1763776984931339",
                "objectApiName2RecordIds": {"package172__c__object_aadeicdjdw6co": [int('{}'.format(res3))]},
                "variables": "[]",
                "version": "v2"}
            res5 = session.post(url=url2, json=data5, headers=headers)
            return res2, res5
        else:
            pass

    def apply(self):
        url = 'https://asset.bytedance.net/api/v1/asset/appropriate/assetApplyActionTaking'  # 领用
        res1 = self.session.get(url=self.get_url()[0], headers=self.headers).json()['data'][
            'ApplyFlowList']  # 领用待接单
        if res1 == []:
            pass
        else:
            for i in range(0, len(res1)):
                id = res1[i]['ID']
                # print(id)
                data = {'flowIDs': ["{}".format(id)], 'description': "接单"}
                res2 = self.session.post(url=url, json=data, headers=self.headers)
                return res2

        # ************************************领用***************************************************************

    def br(self):
        url2 = 'https://asset.bytedance.net/api/v1/asset/appropriate/assetApplyActionTaking'
        url3 = 'https://asset.bytedance.net/api/v1/remark/create/1'
        res3 = self.session.get(url=self.get_url()[1], headers=self.headers).json()['data'][
            'BorrowFlowList']  # 借用待接单

        if res3 == []:
            pass
        else:
            for l in range(0, len(res3)):
                id_2 = res3[l]['ID']
                applyUser = res3[l]['ApplyUser']
                data2 = {"flowIDs": ["{}".format(id_2)], "description": "接单"}
                res4 = requests.post(url=url2, json=data2, headers=self.headers)
                res6 = res3[l]['NameZh']
                if res6 == '主机':
                    pass
                else:
                    data3 = {"id": "{}".format(id_2), "type": 1, "imgUrls": [], "userIds": ["{}".format(applyUser)],
                             "content": "{\"user_index\":0}  同学你好，你借用的设备可以到IT服务台领取了哈"}
                    res5 = self.session.post(url=url3, json=data3, headers=self.headers)

                    return res4, res5

        # ************************************借用***************************************************************

    def repair(self):
        url3 = 'https://asset.bytedance.net/api/v2/common/RepairFlowAction'  # 报修
        url4 = 'https://asset.bytedance.net/api/v2/common/RepairFlowAction'
        res5 = self.session.get(url=self.get_url()[2], headers=self.headers).json()['data']['RepairFlows']
        if res5 == []:
            pass
        else:
            for n in range(0, len(res5)):
                id_3 = res5[n]['ID']
                data3 = {"FlowIDs": ["{}".format(id_3)], "RepairActionType": 201}
                res6 = self.session.post(url=url3, json=data3, headers=self.headers)
                data4 = {"FlowIDs": ["{}".format(id_3)], "RepairActionType": 203}
                res7 = self.session.post(url=url4, json=data4, headers=self.headers)
                return res6, res7

        # ************************************报修***************************************************************

    def back(self):
        url4 = 'https://asset.bytedance.net/api/v1/asset/return/taking'  # 退库
        res7 = self.session.get(url=self.get_url()[3], headers=self.headers).json()['data'][
            'AssetReturnList']  # 退库待接单
        if res7 == []:
            pass
        else:
            for j in range(0, len(res7)):
                id_4 = res7[j]['ID']
                data4 = {"FlowID": "{}".format(id_4),
                         "Assignee": "{}@bytedance.people".format(int(self.number_value))}  # 处理人为自己
                res8 = self.session.post(url=url4, json=data4, headers=self.headers)

                return res8

        # ************************************退库***************************************************************

    def huigou(self):
        url5 = 'https://asset.bytedance.net/api/v1/asset/repurchase/placeOrder'
        res9 = self.session.get(url=self.get_url()[4], headers=self.headers).json()['data'][
            'FlowList']  # 回购待接单
        if res9 == []:
            pass
        else:
            for x in range(0, len(res9)):
                id_5 = res9[x]['BasicInfo']['ID']
                data5 = {"flowIds": ["{}".format(id_5)]}
                res10 = self.session.post(url=url5, json=data5, headers=self.headers)
                return res10

    def main(self):
        if time.localtime().tm_wday + 1 in [1, 2, 3, 4, 5]:
            if 10 <= time.localtime().tm_hour <= 18:
                apply = self.apply()
                br = self.br()
                repair = self.repair()
                back = self.back()
                huigou = self.huigou()
                return apply, br, repair, back, huigou
                # with ThreadPoolExecutor(max_workers=5) as t:
                #     for i in [self.apply(), self.br(), self.repair(), self.back(), self.huigou()]:
                #         t.submit(i)
            else:
                pass
        else:
            pass

    def get_tag(self, cookie_value, pass_value, IT_value):
        self.cookie = cookie_value
        self.pass_value = pass_value
        self.IT_value = IT_value

        url = 'https://apaas.feishuapp.cn/ae/api/v1/workflow/namespaces/itasetpr__c/start'
        url2 = 'https://apaas.feishuapp.cn/ae/api/v1/workflow/namespaces/itasetpr__c/form/completeGlobalForm'
        data = {"sourceWorkflowId": "1715155898616893", "objectId": 1715148060133389}
        headers = {
            'Cookie': '{}'.format(self.cookie),
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
            'X-Kunlun-Token': '{}'.format(self.pass_value)
        }
        session = requests.Session()
        res = session.post(url=url, json=data, headers=headers).json()['data']['data']['formInstanceId']
        # print(res.text)
        null = None
        false = None
        true = None
        data2 = {"form": {
            "_initialRecord__proposed__itasetpr__c__object_aadbp2ym4keaq": {"itasetpr__c__lookup_aadbumvgxwkco": null,
                                                                            "itasetpr__c__lookup_aadbumvgxwmao": {
                                                                                "id": 1747287894237220,
                                                                                "is_deleted": false,
                                                                                "name": "虹桥国际商务广场二期-(Hongqiao Venture International Park Phase II)-7F-普通标签打印机(TD-4520TN)"},
                                                                            "itasetpr__c__lookup_aadcmzcq6v4aq": {
                                                                                "id": 1707865693145095,
                                                                                "is_deleted": false,
                                                                                "name": "虹桥国际商务广场二期-(Hongqiao Venture International Park Phase II)"},
                                                                            "itasetpr__c__option_aadb2mpyyscd4": "itasetpr__c__option_1641227033067_bgq112s",
                                                                            "itasetpr__c__option_aadbp2nuleca2": "itasetpr__c__option_1635698562109_aadbp2nwjxqg2",
                                                                            "itasetpr__c__option_aadbp2nuukia2": "itasetpr__c__option_1638863630376_aadbv4jidzykq",
                                                                            "itasetpr__c__option_aadbp3f57icdo": null,
                                                                            "itasetpr__c__option_aadbumvgxwkbo": "itasetpr__c__option_1638094808604_aadbumvgxwmf4",
                                                                            "itasetpr__c__option_aadbunjokqulo": "itasetpr__c__option_1638097637630_aadbunjokr4h4",
                                                                            "itasetpr__c__option_aaddfafe2acco": "itasetpr__c__option_1663575871175_aaddfafe2acdo",
                                                                            "itasetpr__c__phone_aadbumvgxvud2": null,
                                                                            "itasetpr__c__text_aadbumvgxvgfq": null,
                                                                            "itasetpr__c__text_aadbumvgxvuc2": null,
                                                                            "itasetpr__c__text_aadbumvgxwkdo": "上海市闵行区合川路2671号虹桥国际商务广场二期(Hongqiao Venture International Park Phase II,2671 Hechuan Road, Minhang District, Shanghai)"}},
            "objectId": 1715148060133389,
            "properties": {"_initialRecord__proposed__itasetpr__c__object_aadbp2ym4keaq": {
                "itasetpr__c__option_aadbunjokqulo": {"alias": [],
                                                      "componentId": "_initialRecord_option_aadbunjokqulo_enum",
                                                      "defaultValue": {"type": "value",
                                                                       "value": "itasetpr__c__option_1638097637630_aadbunjokr4h4"},
                                                      "hidden": true, "layout": [], "readonly": true, "required": false,
                                                      "scanEditable": false, "scanEnable": false, "tooltip": [],
                                                      "type": "enum",
                                                      "width": 100},
                "itasetpr__c__option_aaddfafe2acco": {"alias": [],
                                                      "componentId": "_initialRecord_option_aaddfafe2acco_enum",
                                                      "defaultValue": {"type": "value",
                                                                       "value": "itasetpr__c__option_1663575871175_aaddfafe2acdo"},
                                                      "hidden": true, "layout": [], "readonly": false,
                                                      "required": false,
                                                      "scanEditable": true, "scanEnable": false, "tooltip": [],
                                                      "type": "enum",
                                                      "width": 100},
                "itasetpr__c__option_aadbp2nuukia2": {"alias": [],
                                                      "componentId": "_initialRecord_option_aadbp2nuukia2_enum",
                                                      "defaultValue": {"type": "value"}, "layout": [],
                                                      "readonly": false,
                                                      "required": true, "scanEditable": false, "scanEnable": false,
                                                      "tooltip": [], "type": "enum", "width": 50},
                "itasetpr__c__option_aadb2mpyyscd4": {"alias": [],
                                                      "componentId": "_initialRecord_option_aadb2mpyyscd4_enum",
                                                      "defaultValue": {"type": "value"}, "layout": [],
                                                      "readonly": false,
                                                      "required": true, "scanEditable": false, "scanEnable": false,
                                                      "tooltip": [], "type": "enum", "width": 50},
                "itasetpr__c__lookup_aadcmzcq6v4aq": {"alias": [],
                                                      "componentId": "_initialRecord_lookup_aadcmzcq6v4aq_lookup",
                                                      "defaultValue": {"generateRule": "", "reference": null,
                                                                       "type": "value",
                                                                       "value": null}, "layout": [], "placeholder": [],
                                                      "readonly": false, "required": true, "scanEditable": true,
                                                      "scanEnable": false, "tooltip": [], "type": "lookup",
                                                      "width": 100},
                "itasetpr__c__option_aadbp2nuleca2": {"alias": [],
                                                      "componentId": "_initialRecord_option_aadbp2nuleca2_enum",
                                                      "defaultValue": {"type": "value"}, "layout": [],
                                                      "readonly": false,
                                                      "required": true, "scanEditable": false, "scanEnable": false,
                                                      "tooltip": [], "type": "enum", "width": 100},
                "itasetpr__c__option_aadbp3f57icdo": {"alias": [],
                                                      "componentId": "_initialRecord_option_aadbp3f57icdo_enum",
                                                      "defaultValue": {"type": "value"}, "hidden": true, "layout": [],
                                                      "readonly": false, "required": true, "scanEditable": false,
                                                      "scanEnable": false, "tooltip": [], "type": "enum", "width": 100},
                "itasetpr__c__option_aadbumvgxwkbo": {"alias": [],
                                                      "componentId": "_initialRecord_option_aadbumvgxwkbo_enum",
                                                      "defaultValue": {"type": "value"}, "layout": [],
                                                      "readonly": false,
                                                      "required": true, "scanEditable": false, "scanEnable": false,
                                                      "tooltip": [], "type": "enum", "width": 100},
                "itasetpr__c__lookup_aadbumvgxwkco": {"alias": [],
                                                      "componentId": "_initialRecord_lookup_aadbumvgxwkco_lookup",
                                                      "defaultValue": {"generateRule": "", "reference": null,
                                                                       "type": "value",
                                                                       "value": null}, "hidden": true, "layout": [],
                                                      "placeholder": [], "readonly": false, "required": true,
                                                      "scanEditable": false, "scanEnable": false, "tooltip": [],
                                                      "type": "lookup", "width": 50},
                "itasetpr__c__text_aadbumvgxvuc2": {"alias": [],
                                                    "componentId": "_initialRecord_text_aadbumvgxvuc2_text",
                                                    "defaultValue": {"type": "value"}, "hidden": true, "layout": [],
                                                    "placeholder": [], "readonly": false, "required": true,
                                                    "scanEditable": false, "scanEnable": false, "tooltip": [],
                                                    "type": "text",
                                                    "width": 50},
                "itasetpr__c__text_aadbumvgxvgfq": {"alias": [],
                                                    "componentId": "_initialRecord_text_aadbumvgxvgfq_text",
                                                    "defaultValue": {"type": "value"}, "hidden": true, "layout": [],
                                                    "placeholder": [], "readonly": false, "required": true,
                                                    "scanEditable": false, "scanEnable": false, "tooltip": [],
                                                    "type": "text",
                                                    "width": 33},
                "itasetpr__c__phone_aadbumvgxvud2": {"alias": [],
                                                     "componentId": "_initialRecord_phone_aadbumvgxvud2_phone",
                                                     "defaultValue": {"type": "value"}, "hidden": true, "layout": [],
                                                     "placeholder": [], "readonly": false, "required": true,
                                                     "scanEditable": false, "scanEnable": false, "tooltip": [],
                                                     "type": "phone",
                                                     "width": 66},
                "itasetpr__c__text_aadbumvgxwkdo": {"alias": [],
                                                    "componentId": "_initialRecord_text_aadbumvgxwkdo_text",
                                                    "defaultValue": {"type": "value"}, "hidden": true, "layout": [],
                                                    "placeholder": [], "readonly": false, "required": true,
                                                    "scanEditable": false, "scanEnable": false, "tooltip": [],
                                                    "type": "text",
                                                    "width": 100},
                "itasetpr__c__lookup_aadbumvgxwmao": {"alias": [],
                                                      "componentId": "_initialRecord_lookup_aadbumvgxwmao_lookup",
                                                      "defaultValue": {"generateRule": "", "reference": null,
                                                                       "type": "value",
                                                                       "value": null}, "layout": [], "placeholder": [],
                                                      "readonly": false, "required": true, "scanEditable": false,
                                                      "scanEnable": false, "tooltip": [], "type": "lookup",
                                                      "width": 100}}},
            "formInstanceId": int('{}'.format(res)), "sourceWorkflowId": "1715155898616893"}

        res2 = session.post(url=url2, json=data2, headers=headers)
        print(res2.text)
        url3 = 'https://apaas.feishuapp.cn/ae/api/v2/layout/namespaces/itasetpr__c/table/runtime/data'
        data3 = {"describeFilter": {"filter": {"api_name": "", "biz_type": "", "conditions": [{"index": 0,
                                                                                               "left": {
                                                                                                   "displayName": null,
                                                                                                   "fieldsDisplayNames": null,
                                                                                                   "settings": {
                                                                                                       "fieldPath": [{
                                                                                                           "extendLogic": null,
                                                                                                           "extendLogicTags": [],
                                                                                                           "fieldApiName": "_createdBy",
                                                                                                           "fieldId": 0,
                                                                                                           "isMultiple": false,
                                                                                                           "isSubField": false,
                                                                                                           "objectApiName": "itasetpr__c__object_aadbp2ym4keaq",
                                                                                                           "objectId": 0}],
                                                                                                       "valueVersion": "",
                                                                                                       "variableApiName": "current_object",
                                                                                                       "variableType": "lookup"},
                                                                                                   "status": "",
                                                                                                   "type": "metadataVariable"},
                                                                                               "operator": "equals",
                                                                                               "right": {
                                                                                                   "displayName": null,
                                                                                                   "fieldsDisplayNames": null,
                                                                                                   "settings": {
                                                                                                       "fieldPath": [{
                                                                                                           "extendLogic": null,
                                                                                                           "extendLogicTags": [],
                                                                                                           "fieldApiName": "_id",
                                                                                                           "fieldId": 0,
                                                                                                           "isMultiple": false,
                                                                                                           "isSubField": false,
                                                                                                           "objectApiName": "_user",
                                                                                                           "objectId": 0}],
                                                                                                       "valueVersion": "",
                                                                                                       "variableApiName": "current_user",
                                                                                                       "variableType": "lookup"},
                                                                                                   "status": "",
                                                                                                   "type": "metadataVariable"}},
                                                                                              {"index": 0,
                                                                                               "left": {
                                                                                                   "displayName": null,
                                                                                                   "fieldsDisplayNames": null,
                                                                                                   "settings": {
                                                                                                       "fieldPath": [{
                                                                                                           "extendLogic": null,
                                                                                                           "extendLogicTags": [],
                                                                                                           "fieldApiName": "itasetpr__c__lookup_aadbumvgxwmao",
                                                                                                           "fieldId": 0,
                                                                                                           "isMultiple": false,
                                                                                                           "isSubField": false,
                                                                                                           "objectApiName": "itasetpr__c__object_aadbp2ym4keaq",
                                                                                                           "objectId": 0},
                                                                                                           {
                                                                                                               "extendLogic": null,
                                                                                                               "extendLogicTags": [],
                                                                                                               "fieldApiName": "itasetpr__c__lookup_aadbul4ogrmb2",
                                                                                                               "fieldId": 0,
                                                                                                               "isMultiple": false,
                                                                                                               "isSubField": false,
                                                                                                               "objectApiName": "itasetpr__c__object_aadbp2iiwkgc2",
                                                                                                               "objectId": 0}],
                                                                                                       "valueVersion": "",
                                                                                                       "variableApiName": "current_object",
                                                                                                       "variableType": "lookup"},
                                                                                                   "status": "",
                                                                                                   "type": "metadataVariable"},
                                                                                               "operator": "hasAnyOf",
                                                                                               "right": {
                                                                                                   "displayName": null,
                                                                                                   "fieldsDisplayNames": null,
                                                                                                   "settings": {
                                                                                                       "fieldPath": [{
                                                                                                           "extendLogic": null,
                                                                                                           "extendLogicTags": [],
                                                                                                           "fieldApiName": "_id",
                                                                                                           "fieldId": 0,
                                                                                                           "isMultiple": false,
                                                                                                           "isSubField": false,
                                                                                                           "objectApiName": "_user",
                                                                                                           "objectId": 0}],
                                                                                                       "valueVersion": "",
                                                                                                       "variableApiName": "current_user",
                                                                                                       "variableType": "lookup"},
                                                                                                   "status": "",
                                                                                                   "type": "metadataVariable"}}],
                                               "logic": "1 or 2", "use_fx_editor": "", "use_type": "", "version": "v2"},
                                    "appFilterIndex": []}, "size": 20, "page": 1,
                 "authorize": {"appId": 1715070808989757, "appPageName": "4ami6ffi6qjfq5_ylcw44h"},
                 "fields": ["itasetpr__c__autoid_aadbp2nuukgd2", "itasetpr__c__option_aadbunjokqulo",
                            "itasetpr__c__option_aadbp2nuukia2", "itasetpr__c__option_aadb2mpyyscd4",
                            "itasetpr__c__lookup_aadcmzcq6v4aq", "itasetpr__c__option_aadbp2nuleca2",
                            "itasetpr__c__option_aadbp3f57icdo", "itasetpr__c__option_aadbumvgxwkbo",
                            "itasetpr__c__lookup_aadbumvgxwkco", "itasetpr__c__text_aadbumvgxvuc2",
                            "itasetpr__c__text_aadbumvgxvgfq", "itasetpr__c__phone_aadbumvgxvud2",
                            "itasetpr__c__text_aadbumvgxwkdo", "itasetpr__c__lookup_aadbumvgxwmao",
                            "itasetpr__c__text_aadbumvgxvyfo", "itasetpr__c__lookup_aaddd3tjqtab4", "_createdBy",
                            "_createdAt",
                            "_id"], "objectId": 1715148060133389, "objectApiName": "itasetpr__c__object_aadbp2ym4keaq",
                 "actions": [{"objectId": 1715148060133389, "actionId": 1717672140699815,
                              "field": {"fieldApiName": "_id", "fieldLabel": [],
                                        "objectApiName": "itasetpr__c__object_aadbp2ym4keaq",
                                        "objectLabel": [
                                            {"language_code": 2052, "text": "资产标签及号段管理-标签打印申请"}],
                                        "targetObjectApiName": "itasetpr__c__object_aadbp2ym4keaq",
                                        "targetObjectLabel": [
                                            {"language_code": 2052, "text": "资产标签及号段管理-标签打印申请"}]}},
                             {"objectId": 1715148060133389, "actionId": 1720635989010471,
                              "field": {"fieldApiName": "_id", "fieldLabel": [],
                                        "objectApiName": "itasetpr__c__object_aadbp2ym4keaq", "objectLabel": [
                                      {"language_code": 1033, "text": "IT Asset Tag and Range - Print Request"},
                                      {"language_code": 2052, "text": "资产标签及号段管理-标签打印申请"}],
                                        "targetObjectApiName": "itasetpr__c__object_aadbp2ym4keaq",
                                        "targetObjectLabel": [
                                            {"language_code": 1033, "text": "IT Asset Tag and Range - Print Request"},
                                            {"language_code": 2052, "text": "资产标签及号段管理-标签打印申请"}]}}],
                 "fromComponent": "table"}
        res3 = session.post(url=url3, json=data3, headers=headers).json()['data']['items'][0]['recordId']
        data4 = {"sourceWorkflowId": "1715164939901992", "objectId": 1715148060133389,
                 "recordId": int('{}'.format(res3))}
        res4 = session.post(url=url, json=data4, headers=headers).json()['data']['data']['form']['variable_bgq85qy'][
            'itasetpr__c__lookup_aadbp3f57ieao']['name']
        res5 = session.post(url=url, json=data4, headers=headers).json()['data']['data']['formInstanceId']
        _list = re.split('\W+', self.IT_value)
        # print(_list)
        for i in _list:
            if not re.match(r'^IT', i):
                _list.remove(i)
        for j in _list:
            data5 = {"form": {"_initialRecord__proposed__itasetpr__c__object_aadbp2ym4keaq": {
                "itasetpr__c__option_aadbp2nuleca2": "itasetpr__c__option_1635698562109_aadbp2nwjxqg2"},
                "variable_bgq85qy": {
                    "itasetpr__c__lookup_aadbp3f57ieao": {"id": int('{}'.format(res3)), "is_deleted": false,
                                                          "name": "{}".format(res4)},
                    "itasetpr__c__number_aadb3pmpj3oeq": null, "itasetpr__c__option_aadbunjokrqb2": null,
                    "itasetpr__c__text_aadb2qnefpqbq": null, "itasetpr__c__text_aadbp2nulecb2": "{}".format(j),
                    "itasetpr__c__text_aadbp2nxz4iio": null, "itasetpr__c__text_aadbuma254oc4": null,
                    "itasetpr__c__text_aadbuma5an2dq": null}}, "objectId": 1715148060133389,
                "recordId": int('{}'.format(res3)),
                "properties": {"variable_bgq85qy": {"itasetpr__c__lookup_aadbp3f57ieao": {"alias": [],
                                                                                          "componentId": "variable_bgq85qy_lookup_aadbp3f57ieao_lookup",
                                                                                          "defaultValue": {
                                                                                              "generateRule": "",
                                                                                              "reference": null,
                                                                                              "type": "value",
                                                                                              "value": null},
                                                                                          "hidden": true, "layout": [],
                                                                                          "placeholder": [],
                                                                                          "readonly": true,
                                                                                          "required": false,
                                                                                          "scanEditable": false,
                                                                                          "scanEnable": false,
                                                                                          "tooltip": [],
                                                                                          "type": "lookup",
                                                                                          "width": 100},
                                                    "itasetpr__c__number_aadb3pmpj3oeq": {"alias": [],
                                                                                          "componentId": "variable_bgq85qy_number_aadb3pmpj3oeq_float",
                                                                                          "defaultValue": {
                                                                                              "type": "value"},
                                                                                          "layout": [], "placeholder": [
                                                            {"language_code": 1033,
                                                             "text": "The printing will follow the sequence number from 1-10"},
                                                            {"language_code": 2052,
                                                             "text": "打印会按照顺序号，从1-10……"}],
                                                                                          "readonly": false,
                                                                                          "required": false,
                                                                                          "scanEditable": false,
                                                                                          "scanEnable": false,
                                                                                          "tooltip": [
                                                                                              {"language_code": 1033,
                                                                                               "text": "If this item is filled in, it will be printed in order. If it is not filled in, it will be printed in the order of asset number from smallest to largest"},
                                                                                              {"language_code": 2052,
                                                                                               "text": "如果填写此项会按照顺序打印，如果不填写，会按照资产号的从小到大的顺序打印"}],
                                                                                          "type": "float",
                                                                                          "width": 100},
                                                    "itasetpr__c__text_aadbp2nulecb2": {"alias": [],
                                                                                        "componentId": "variable_bgq85qy_text_aadbp2nulecb2_text",
                                                                                        "defaultValue": {
                                                                                            "type": "value"},
                                                                                        "layout": [], "placeholder": [],
                                                                                        "readonly": false,
                                                                                        "required": true,
                                                                                        "scanEditable": false,
                                                                                        "scanEnable": false,
                                                                                        "tooltip": [],
                                                                                        "type": "text", "width": 100},
                                                    "itasetpr__c__option_aadbunjokrqb2": {"alias": [],
                                                                                          "componentId": "variable_bgq85qy_option_aadbunjokrqb2_enum",
                                                                                          "defaultValue": {
                                                                                              "type": "value"},
                                                                                          "hidden": true, "layout": [],
                                                                                          "readonly": false,
                                                                                          "required": true,
                                                                                          "scanEditable": false,
                                                                                          "scanEnable": false,
                                                                                          "tooltip": [],
                                                                                          "type": "enum", "width": 100},
                                                    "itasetpr__c__text_aadbp2nxz4iio": {"alias": [],
                                                                                        "componentId": "variable_bgq85qy_text_aadbp2nxz4iio_text",
                                                                                        "defaultValue": {
                                                                                            "type": "value"},
                                                                                        "hidden": true, "layout": [],
                                                                                        "placeholder": [],
                                                                                        "readonly": false,
                                                                                        "required": true,
                                                                                        "scanEditable": false,
                                                                                        "scanEnable": false,
                                                                                        "tooltip": [],
                                                                                        "type": "text", "width": 100},
                                                    "itasetpr__c__text_aadbuma254oc4": {"alias": [],
                                                                                        "componentId": "variable_bgq85qy_text_aadbuma254oc4_text",
                                                                                        "defaultValue": {
                                                                                            "type": "value"},
                                                                                        "hidden": true, "layout": [],
                                                                                        "placeholder": [],
                                                                                        "readonly": false,
                                                                                        "required": true,
                                                                                        "scanEditable": false,
                                                                                        "scanEnable": false,
                                                                                        "tooltip": [],
                                                                                        "type": "text", "width": 100},
                                                    "itasetpr__c__text_aadbuma5an2dq": {"alias": [],
                                                                                        "componentId": "variable_bgq85qy_text_aadbuma5an2dq_text",
                                                                                        "defaultValue": {
                                                                                            "type": "value"},
                                                                                        "hidden": true, "layout": [],
                                                                                        "placeholder": [],
                                                                                        "readonly": false,
                                                                                        "required": true,
                                                                                        "scanEditable": false,
                                                                                        "scanEnable": false,
                                                                                        "tooltip": [],
                                                                                        "type": "text", "width": 100},
                                                    "itasetpr__c__text_aadb2qnefpqbq": {
                                                        "componentId": "variable_bgq85qy_text_aadb2qnefpqbq_text",
                                                        "defaultValue": {"type": "value"}, "layout": [],
                                                        "readonly": false,
                                                        "required": false, "scanEditable": false, "scanEnable": false,
                                                        "type": "text", "width": 100}},
                               "_initialRecord__proposed__itasetpr__c__object_aadbp2ym4keaq": {
                                   "itasetpr__c__option_aadbp2nuleca2": {"alias": [],
                                                                         "componentId": "_initialRecord_option_aadbp2nuleca2_enum",
                                                                         "defaultValue": {"type": "value"},
                                                                         "hidden": true,
                                                                         "layout": [], "readonly": true,
                                                                         "required": false,
                                                                         "scanEditable": false, "scanEnable": false,
                                                                         "tooltip": [], "type": "enum", "width": 100}}},
                "formInstanceId": int('{}'.format(res5)), "sourceWorkflowId": "1715164939901992"}
            res6 = session.post(url=url2, json=data5, headers=headers)
        data6 = {"actions": [1715155898617869, 1715156392492110], "actionsWithRecord": [
            {"actionIds": [1717669119955976, 1715164943866919, 1718392803146808], "objectId": 1715148060133389,
             "recordId": int('{}'.format(res3))}],
                 "actionsWithMultiRecord": [{"actionId": 1749625123705899, "recordSetting": [
                     {"type": "record", "variableApiName": "customizeInput__original__cd232d77",
                      "setting": {"objectId": 1715148060133389, "recordId": int('{}'.format(res3))}}]}]}
        url4 = 'https://apaas.feishuapp.cn/ae/api/v1/biz-api/namespaces/itasetpr__c/appData/authorizedActionsV2'
        res7 = session.post(url=url4, json=data6, headers=headers).json()['data'][2]['behavior']['triggerWorkflow'][
            'source_workflow_id']
        data7 = {"sourceWorkflowId": "{}".format(res7), "objectId": 1715148060133389,
                 "recordId": int('{}'.format(res3))}
        res8 = session.post(url=url, json=data7, headers=headers)
        data8 = {"actions": [1715156392492110], "actionsWithRecord": [
            {"actionIds": [1715164943866919, 1718392803146808], "objectId": 1715148060133389,
             "recordId": int('{}'.format(res3))}],
                 "actionsWithMultiRecord": [{"actionId": 1749625123705899, "recordSetting": [
                     {"type": "record", "variableApiName": "customizeInput__original__cd232d77",
                      "setting": {"objectId": 1715148060133389, "recordId": int('{}'.format(res3))}}]}]}
        res9 = session.post(url=url4, json=data8, headers=headers).json()['data'][1]['behavior']['triggerWorkflow'][
            'source_workflow_id']
        data9 = {"sourceWorkflowId": "{}".format(res9), "objectId": 1715148060133389,
                 "recordId": int('{}'.format(res3))}
        res10 = session.post(url=url, json=data9, headers=headers)
        return res8, res10


@app.route('/index')
def index():
    return render_template('资产.html')


@app.route('/applyForReturn', methods=['POST'])
def applyForReturn():
    data = request.get_data()
    json_data = json.loads(data)
    checkbox_value = json_data.get("site")
    text_value = json_data.get('pass')
    number_value = json_data.get('number')
    number2_value = json_data.get('number2')
    # print(checkbox_value,text_value,number_value,number2_value)
    output = ITAM(checkbox_value, text_value, number_value)
    output.apply_return(number2_value)
    info = dict()
    info['message'] = '{}已发起退库'.format(number2_value)
    return jsonify(info)


@app.route('/directReturn', methods=['POST'])
def directReturn():
    data = request.get_data()
    json_data = json.loads(data)
    checkbox_value = json_data.get("site")
    text_value = json_data.get('pass')
    number_value = json_data.get('number')
    number2_value = json_data.get('number2')
    cookie_value = json_data.get('cookie_value')
    pass_value = json_data.get('pass_value')
    output = ITAM(checkbox_value, text_value, number_value)
    output.dic_return(number2_value)
    output.erase(cookie_value, pass_value)
    info = dict()
    info['message'] = '{}已退库,并发起擦除'.format(number2_value)
    return jsonify(info)


@app.route('/autoAcceptOrder', methods=['POST'])
def autoAcceptOrder():
    data = request.get_data()
    json_data = json.loads(data)
    checkbox_value = json_data.get("site")
    text_value = json_data.get('pass')
    number_value = json_data.get('number')
    output = ITAM(checkbox_value, text_value, number_value)
    output.main()
    info = dict()
    info['message'] = '{}正在接单中'.format(checkbox_value)
    info["time"] = datetime.datetime.now()
    return jsonify(info)


@app.route('/get_tar', methods=['POST'])
def get_tar():
    html_data = request.get_data()
    json_html_data = json.loads(html_data)
    cookie_value = json_html_data.get('cookie_value')
    pass_value = json_html_data.get('pass_value')
    IT_value = json_html_data.get('IT_value')
    checkbox_value = json_html_data.get("site")
    text_value = json_html_data.get('pass')
    number_value = json_html_data.get('number')
    output = ITAM(checkbox_value, text_value, number_value)
    output.get_tag(cookie_value, pass_value, IT_value)
    info = dict()
    info['message'] = '此次已打印'
    return jsonify(info)


if __name__ == '__main__':
    app.run(host='10.68.46.247')
    app.run(host='10.93.221.170')
